package com.haoting.blogservice.controller;


import com.haoting.blogservice.entity.Blogsubject;
import com.haoting.blogservice.entity.subject.OneSubject;
import com.haoting.blogservice.service.BlogsubjectService;
import com.haoting.commonutils.CommonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tingting
 * @since 2020-12-21
 */
@Api(tags = "文章分类管理")
@RestController
@RequestMapping("/blogservice/blogsubject")
//@CrossOrigin
public class BlogsubjectController {

    @Autowired
    BlogsubjectService blogsubjectService;

    //添加文章分类
    @PostMapping("addSubject")
    public CommonResult addSubject(MultipartFile file){

        blogsubjectService.saveSubject(file,blogsubjectService);
        return CommonResult.ok();
    }

    //课程分类列表(树形)
    @GetMapping("getAllSubject")
    public CommonResult getAllSubject(){
        List<OneSubject> list = blogsubjectService.getAllOneTwoSubject();
        return CommonResult.ok().data("list",list);
    }
    @GetMapping("getSubjectById/{id}")
    public CommonResult getSubjectById(@PathVariable String id){
        Blogsubject blogsubject = blogsubjectService.getById(id);
        String subjectName = blogsubject.getTitle();
        return CommonResult.ok().data("subjectName",subjectName);
    }
}

